package config

import (
	"gitee.com/crack007/goose/config"
	"github.com/gorilla/websocket"
)

var etcdConfig *EtcdConfig
var NodeConfig *nodeConfig
var rabbitmqConfig *RabbitmqConfig
var snowflakeConfig *SnowflakeConfig
var WsConfig *wsConfig
var MsgConfig *msgConfig
var KafkaConfig *kafkaConfig
var GrpcConfig = &grpcConfig{}

func InitAppConfig() {
	etcdConfig = &EtcdConfig{
		Endpoints:   config.GetStringSlice("etcd.endpoints", nil),
		Dialtimeout: config.GetInt("etcd.dial_timeout", 0),
	}
	NodeConfig = &nodeConfig{
		NodeName: config.GetString("app.node_name", ""),
		NodeAddr: config.GetString("app.node_addr", ""),
		NodePort: uint16(config.GetUint("app.node_port", 0)),
		Timeout:  config.GetUint32("app.timeout", 500),
	}
	rabbitmqConfig = &RabbitmqConfig{
		User:     config.GetString("rabbitmq.user", ""),
		Password: config.GetString("rabbitmq.password", ""),
		Host:     config.GetString("rabbitmq.host", ""),
		Port:     config.GetInt("rabbitmq.port", 0),
		Vhost:    config.GetString("rabbitmq.vhost", ""),
	}
	snowflakeConfig = &SnowflakeConfig{}
	WsConfig = &wsConfig{
		IdleTimeout:   uint(config.GetInt("ws.idle_timeout", 0)),
		IdleCount:     uint(config.GetInt("ws.idle_count", 0)),
		MsgType:       config.GetInt("ws.msg_type", websocket.TextMessage),
		PushQueueSize: config.GetUint("ws.push_queue_size", 0xffff),
		GrpcPort:      uint16(config.GetUint("grpc.ws.port", 30000)),
	}
	MsgConfig = &msgConfig{
		DbQueueSize: config.GetUint("msg.db_queue_size", 0xffff),
	}
	KafkaConfig = &kafkaConfig{
		Host:  config.GetStringSlice("kafka.host", nil),
		Topic: config.GetString("kafka.topic", "im"),
	}
	GrpcConfig.Port = uint16(config.GetUint("grpc.ws.port", 0))
}
